package com.labor_management_system.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.labor_management_system.Entity.Team;
import com.labor_management_system.Service.TeamService;
import com.labor_management_system.Mapper.TeamMapper;
import com.labor_management_system.Utils.Pair;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author deathwing475
* @description 针对表【team】的数据库操作Service实现
* @createDate 2024-02-27 09:55:00
*/
@Service
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team>
    implements TeamService {
    @Override
    public List<String> getAllTeamID() {

        return baseMapper.selectList(null).stream().map(Team::getTeamId).collect(Collectors.toList());
    }

    @Override
    public List<Team> getAllTeam() {
        return baseMapper.selectList(null);
    }

    @Override
    public List<Team> getTeamByName(String teamName) {
        return baseMapper.selectList(new QueryWrapper<Team>().like("team_name",teamName));
    }

    @Override
    public List<Pair<String, String>> getTeamIDAndName() {
        List<Team> t = baseMapper.selectList(null);
        List<Pair<String, String>> backlist= new ArrayList<>();
        for(Team p : t){
            Pair<String, String> s = new Pair<>(p.getTeamId(),p.getTeamName());
            backlist.add(s);
        }
        return backlist;
    }

    @Override
    public boolean insertTeam(Team team) {
        return false;
    }

    @Override
    public boolean deleteByID(String teamID) {
        return false;
    }
    //班组

    @Override
    public List<Team> selectAllTeam() {
        return baseMapper.selectList(null);
    }

    @Override
    public Team slectTeamById(String teamId) {

        QueryWrapper<Team> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("team_id",teamId);

        return baseMapper.selectOne(queryWrapper);
    }

}




